#include<iostream>
 
using namespace std;

struct Node
{
    string sno;
    int month;
    Node*next;
    int day;
};
//把结点S插入到头指针为head的有序连表中
//插入后连表仍然有序,并返回新链表的头指针
Node *insertNode(Node*head,Node*s)
{
    Node *pre = NULL,*p = head;
    while (p!=NULL && p->month*100+p->day  <= s->month*100+s->day)
    {
        pre = p;
        p = p->next;
    }
    s->next = p;
if (pre == NULL)
{
    head = s;
}
else
{
    pre->next = s;
}

return head;
}
//2.插入操作
void display(Node* head)

{
    if(head == NULL || head>next == NULL) return ;                                     
    Node *p = head;//初始时，让p指针指向第一个节点
    while (p)
    {
        cout<<p->sno<<" "<<p->month<<" "<<p->day<<endl;

        p = p->next;
    }
    
}

int main()
{
int n;
Node *s,*head = NULL;
cin>>n;
for (int i = 1; i <=n; i++)
{
    s = new Node;
    cin>>s->sno>>s->month>>s->day;
    head = insertNode(head,s);

}
    display(head);




    return 0;
}